<?php
/**
 * This is interface for storage engine
 * @package     nuo
 * @subpackage  nuo.storage
 * @author      Nam Nguyen <nam.ngvan@gmail.com>
 * @version     1.0
 * @since       Apr 19, 2013
 */
abstract class Nuo_Storage_Abstract
{

	/**
	 * Storage id
	 * @access  protected
	 * @var     int
	 */
	protected $_id = 0;

	/**
	 * Remote base url, ended by "/"
	 * @access  protected
	 * @var     string
	 */
	protected $_baseUrl = '';

	/**
	 * Base path, ended by "/"
	 * @access  protected
	 * @var     string
	 */
	protected $_basePath = '';

	/**
	 * @abstract
	 * @access  public
	 * @param   string  $path in database
	 * @param   string  $local
	 * @return  data|false
	 * @throws  Exception
	 */
	abstract function get($path, $local);

	/**
	 * @abstract
	 * @access   public
	 * @param    string  $path relative path in database
	 * @param    string  $local
	 * @return   data|FALSE
	 * @throws   Exception
	 */
	abstract function put($path, $local);

	/**
	 * @abstract
	 * @access   public
	 * @param    string  $path relative path in database
	 * @return   data|FALSE
	 * @throws   Exception
	 */
	abstract function delete($path);

	/**
	 * @abstract
	 * @access   public
	 * @param    string $path relative path in database
	 * @return   string|FALSE
	 * @throws   Exception
	 */
	abstract function getContents($path);

	/**
	 * @abstract
	 * @access   public
	 * @param    string $path relative path in database
	 * @param    string $data
	 * @return   string|FALSE
	 * @throws   Exception
	 */
	abstract function putContents($path, $data);

	/**
	 * @access   public
	 * @return   int
	 */
	public function getId()
	{
		return $this -> _id;
	}

	/**
	 * @access   public
	 * @var      int id
	 */
	public function setId($id)
	{
		$this -> _id = (int)$id;
		return $this;
	}

	/**
	 * @access   public
	 * @param    string $baseUrl
	 * @return   Nuo_Storage_Abstract
	 */
	public function setBaseUrl($baseUrl)
	{
		$this -> _baseUrl = rtrim($baseUrl, '/') . '/';
		return $this;
	}

	/**
	 * @access   public
	 * @return   string
	 */
	public function getBaseUrl()
	{
		return $this -> _baseUrl;
	}

	/**
	 * @access   public
	 * @param    string $baseUrl
	 * @return   Nuo_Storage_Abstract
	 */
	public function setBasePath($basePath)
	{
		$this -> _basePath = rtrim($basePath, '/') . '/';
		return $this;
	}

	/**
	 * @access   public
	 * @return   string
	 */
	public function getBasePath($basePath)
	{
		return $this -> _basePath;
	}

	/**
	 * @access   public
	 * @param    string $path
	 * @return   string
	 */
	function getUrl($path)
	{
		return $this -> getBaseUrl() . $path;
	}

	/**
	 * @access   public
	 * @param    string  $path
	 * @return   string
	 */
	function getPath($path)
	{
		return $this -> _basePath . $path;
	}
}
